* Open log
log using session

* Set working directory *

* Clean up
clear all

* Set working directory
cd "/Users/vicentevalentim/Dropbox/Referendums/"

* TABLE 1

* Open data
use data/referendums_data/data_referendum_level_long_final, clear

* Run analysis
regr vote official##rrps_support_position_dummy i.referendum_code, cluster(referendum_code)
est store staged_dem1

* Make table
esttab staged_dem1   using "drafts/staged_dem.tex", tex se replace nomtitles keep(1.official 1.rrps_support_position_dummy 1.official#1.rrps_support_position_dummy _cons) coeflabels (1.official "Official vote (dummy)" 1.rrps_support_position_dummy "Any FRP supports position (dummy)" 1.official#1.rrps_support_position_dummy "Official vote x Any FRP supports position" _cons "Constant") star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include referendum fixed effects" "The outcome is the support for each referendum position, be it official or declared in surveys") 

* TABLE 2
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store main_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store main_2
estadd local  Errors "Bootstrapped"

* Make table
esttab main_1  main_2  using "drafts/main_table.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* FIGURE 2
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

reg minority_groups own_party_position_surplus 
regsave own_party_position_surplus using "results/first_others.dta", ci replace addlabel (Election, fake, Errors, fake)

reg minority_groups rad_right_party own_party_position_surplus interaction4 if date == 198310, r
regsave interaction4 using "results/first_others.dta", ci append level(90) addlabel (Election, "First election (1983)", Errors, Clustered)

xtreg minority_groups own_party_position_surplus interaction4 i.date if date != 198310, fe cluster(party_code_cmp)
regsave interaction4 using "results/first_others.dta", ci append level(90) addlabel (Election, "Subsequent elections", Errors, Clustered)


* FIGURE 3
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Fake model to start dataset with results
reg minority_groups own_party_position_surplus 
regsave own_party_position_surplus using "results/by_topic.dta", ci replace addlabel (Topic, fake, Errors, fake)

local topics own_pos_surplus_aggriculture own_pos_surplus_culture own_pos_surplus_economy own_pos_surplus_education own_pos_surplus_energy own_pos_surplus_environment own_pos_surplus_foreign own_pos_surplus_finance own_pos_surplus_security own_pos_surplus_socpolicy own_pos_surplus_stateorg own_pos_surplus_traffic

foreach topic in `topics' {
		xtreg minority_groups c.rad_right_party##c.`topic' i.date, fe cluster(party_code_cmp)
		regsave c.rad_right_party#c.`topic' using "results/by_topic.dta", ci append addlabel (Topic, `topic', Errors, Clustered standard errors)
		
		xtreg minority_groups c.rad_right_party##c.`topic' i.date, fe vce(bootstrap, seed(2408))
		regsave c.rad_right_party#c.`topic' using "results/by_topic.dta", ci append addlabel (Topic, `topic', Errors, Bootstrapped standard errors)
}


* TABLE B1
* open data
use data/referendums_data/data_referendum_level_long_final, clear

* Run analysis
regr vote official##c.no_rrps_supporting_position i.referendum_code, cluster(referendum_code)
est store staged_dem2

* Make table
esttab staged_dem2   using "drafts/staged_dem2.tex", tex se replace nomtitles keep(1.official no_rrps_supporting_position 1.official#c.no_rrps_supporting_position _cons) coeflabels (1.official "Official vote (dummy)" no_rrps_supporting_position "Number of FRPs supporting position" 1.official#c.no_rrps_supporting_position "Official vote x No. of FRPs supporting position" 1.rrps_support_position_dummy "Any FRP supports position (dummy)" 1.official#1.rrps_support_position_dummy "Official vote x Any FRP supports position" _cons "Constant") star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include referendum fixed effects" "The outcome is the support for each referendum position, be it official or declared in surveys") 

* TABLE B3
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus i.date if rad_right_party == 1, fe cluster(party_code_cmp)
est store split_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus i.date if rad_right_party == 0, fe cluster(party_code_cmp)
est store split_2
estadd local  Errors "Clustered"

* Model 3
xtreg minority_groups own_party_position_surplus i.date if rad_right_party == 1, fe vce(bootstrap, seed(2408))
est store split_3
estadd local  Errors "Bootstrapped"

* Model 4
xtreg minority_groups own_party_position_surplus i.date if rad_right_party == 0, fe vce(bootstrap, seed(2408))
est store split_4
estadd local  Errors "Bootstrapped"

* Make table
esttab split_1  split_2  split_3 split_4 using "drafts/split_sample.tex", tex se replace mtitles("Far-right parties" "Other parties" "Far-right parties" "Other parties" ) keep(own_party_position_surplus _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") scalars(e(N))

* TABLE B4
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups c.own_party_position_surplus_prop##rad_right_party i.date, fe cluster(party_code_cmp)
est store prop_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups c.own_party_position_surplus_prop##rad_right_party i.date, fe vce(bootstrap, seed(2408))
est store prop_2
estadd local  Errors "Bootstrapped"

* Make table
esttab prop_1  prop_2  using "drafts/prop.tex", tex se replace nomtitles keep(own_party_position_surplus_prop 1.rad_right_party#c.own_party_position_surplus_prop _cons) coeflabels (own_party_position_surplus_prop "Mean electoral surplus in party's position (proportion)" 1.rad_right_party#c.own_party_position_surplus_prop "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") scalars(e(N))

* TABLE B5
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Mode 1
xtreg minority_groups_lag own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store lagged_outcome_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups_lag own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store lagged_outcome_2
estadd local  Errors "Bootstrapped"

* Make table
esttab lagged_outcome_1  lagged_outcome_2  using "drafts/lagged_outcome.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party and year fixed effects") scalars(e(N))

* TABLE B6
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg log_minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store logged_1
estadd local  Errors "Clustered"

* Model 2
xtreg log_minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store logged_2
estadd local  Errors "Bootstrapped"

* Make table
esttab logged_1  logged_2  using "drafts/logged.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party and year fixed effects") scalars(e(N))

* TABLE B7
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe r
est store errors_1
estadd local  Errors "Robust"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(jackknife)
est store errors_2
estadd local  Errors "Jackknife"

* Make table
esttab errors_1  errors_2 using "drafts/errors.tex", tex se replace keep(own_party_position_surplus interaction4 _cons) mtitles("Robust standard errors" "Jackknife standard errors") coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") scalars(e(N))

* TABLE B8
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4, fe cluster(party_code_cmp)
est store only_partyfe_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4, fe vce(bootstrap, seed(2408))
est store only_partyfe_2
estadd local  Errors "Bootstrapped"

* Make table
esttab only_partyfe_1 only_partyfe_2  using "drafts/only_party_fe.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party fixed effects") scalars(e(N))

* FIGURE B6
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Fake model to start dataset with results
reg minority_groups own_party_position_surplus 
regsave own_party_position_surplus using "results/jk_dates.dta", ///
ci replace addlabel (Errors, fake, Date, 0)

* Local with dates to remove
local dates 198310 198710 199110 199510 199910 200310 200710 201110 201510 201910

* Loop over these dates to run analyses
foreach date in `dates' {
	
	xtreg minority_groups own_party_position_surplus interaction4 i.date if date != `date', fe cluster(party_code_cmp) 
	regsave interaction4 using "results/jk_dates.dta", ci append addlabel (Errors, Clustered standard errors, Date, `date')


	xtreg minority_groups own_party_position_surplus interaction4 i.date if date != `date', fe vce(bootstrap, seed(2408))
	regsave interaction4 using "results/jk_dates.dta", ci append addlabel (Errors, Bootstrapped standard errors, Date, `date')

}

* FIGURE B7
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Fake model to start dataset with results
reg minority_groups own_party_position_surplus 
regsave own_party_position_surplus using "results/jk_parties.dta", ci replace addlabel (Errors, fake, Party, 0)

* Local with party codes to remove
local parties 43110 43120 43220 43320 43321 43420 43520 43530 43531 43540 43710 43711 43810 43811 43901 43951

* Loop over these parties to run analyses
foreach party in `parties' {
		xtreg minority_groups own_party_position_surplus interaction4 i.date if party_code_cmp != `party', fe cluster(party_code_cmp)
		regsave interaction4 using "results/jk_parties.dta", ci append addlabel (Errors, Clustered standard errors, Date, `date', Party, `party')

		xtreg minority_groups own_party_position_surplus interaction4 i.date if party_code_cmp != `party', fe vce(bootstrap, seed(2408))
		regsave interaction4 using "results/jk_parties.dta", ci append addlabel (Errors, Bootstrapped standard errors, Party, `party')

}

* TABLE B9
* Open data that contains initiatives only
use data/referendums_data/data_both_plus_cmp_collapsed_onlyinitiatives.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store initiatives_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store initiatives_2
estadd local  Errors "Bootstrapped"

* Effect for referendums that are not initiatives
* Open data that contains only referendums that are not initiatives
use data/referendums_data/data_both_plus_cmp_collapsed_onlynotinitiatives.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 3
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store notinitiatives_1
estadd local  Errors "Clustered"

* Model 4
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store notinitiatives_2
estadd local  Errors "Bootstrapped"

* Make table
esttab initiatives_1  initiatives_2 notinitiatives_1  notinitiatives_2  using "drafts/initiatives.tex", tex se replace mtitles ("Initiatives" "Initiatives" "Not initiatives" "Not initiatives") keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* TABLE B10
* Open data
use data/referendums_data/data_both_plus_cmp_collapsed_onlynotsponsored, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store not_sponsored_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store not_sponsored_2
estadd local  Errors "Bootstrapped"

* Make table
esttab not_sponsored_1 not_sponsored_2 using "drafts/notsponsored.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* FIGURE B8
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

reg minority_groups rad_right_party own_party_position_surplus interaction4 if date == 198310, r
regsave interaction4 using "results/first_others.dta", ci append level(90) addlabel (Election, "First election (1983)", Errors, Bootstrapped standard errors)

xtreg minority_groups own_party_position_surplus interaction4 i.date if date != 198310, fe vce(bootstrap, seed(2408))
regsave interaction4 using "results/first_others.dta", ci append level(90) addlabel (Election, "Subsequent elections", Errors, Bootstrapped standard errors)

* TABLE B11
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups rad_right_party c.own_party_position_surplus##rad_right_party##c.year i.year, fe cluster(party_code_cmp)
est store interaction_with_year_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups rad_right_party c.own_party_position_surplus##rad_right_party##c.year, fe vce(bootstrap, seed(2408))
est store interaction_with_year_2
estadd local  Errors "Bootstrapped"

* Make table
esttab interaction_with_year_1  interaction_with_year_2  using "drafts/interaction_with_year.tex", tex se replace nomtitles keep(own_party_position_surplus 1.rad_right_party#c.own_party_position_surplus c.own_party_position_surplus#c.year  1.rad_right_party#c.year 1.rad_right_party#c.own_party_position_surplus#c.year _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" 1.rad_right_party#c.own_party_position_surplus "Far right party x Electoral surplus" c.own_party_position_surplus#c.year "Electoral surplus x Election year" 1.rad_right_party#c.year "Far right party x Election year" 1.rad_right_party#c.own_party_position_surplus#c.year "Far right party x Electoral surplus x Election year" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party fixed effects") scalars(e(N))

* TABLE B12
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date if pervote_lag > 15.762, fe cluster(party_code_cmp)
est store relevant_parties_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date if pervote_lag > 15.762, fe vce(bootstrap, seed(2408))
est store relevant_parties_2
estadd local  Errors "Bootstrapped"

* Make table
esttab relevant_parties_1  relevant_parties_2  using "drafts/relevant_parties.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* TABLE B13
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* When party's position wins
* Open data
use data/referendums_data/data_both_plus_cmp_collapsed_onlywinningpositions, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store winning_position_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store winning_position_2
estadd local  Errors "Bootstrapped"

* When party's position loses
* Open data
use data/referendums_data/data_both_plus_cmp_collapsed_onlylosingpositions, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 3
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store losing_position_1
estadd local  Errors "Clustered"

* Model 4
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store losing_position_2
estadd local  Errors "Bootstrapped"

* Make table
esttab winning_position_1 winning_position_2  losing_position_1 losing_position_2  using "drafts/winning_position.tex", tex se replace mtitles ("Winning positions" "Winning positions" "Losing positions" "Losing positions" ) keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* TABLE B14
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date if party_name != "sps", fe cluster(party_code_cmp)
est store removing_sps_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date if party_name != "sps", fe vce(bootstrap, seed(2408))
est store removing_sps_2
estadd local  Errors "Bootstrapped"

* Model 3
xtreg minority_groups own_party_position_surplus interaction4 i.date if party_name != "ucsp", fe cluster(party_code_cmp)
est store removing_ucsp_1
estadd local  Errors "Clustered"

* Model 4
xtreg minority_groups own_party_position_surplus interaction4 i.date if party_name != "ucsp", fe vce(bootstrap, seed(2408))
est store removing_ucsp_2
estadd local  Errors "Bootstrapped"

* Model 5
xtreg minority_groups own_party_position_surplus interaction4 i.date if party_name != "ucsp" & party_name != "sps", fe cluster(party_code_cmp)
est store removing_both_1
estadd local  Errors "Clustered"

* Model 6
xtreg minority_groups own_party_position_surplus interaction4 i.date if party_name != "ucsp" & party_name != "sps", fe vce(bootstrap, seed(2408))
est store removing_both_2
estadd local  Errors "Bootstrapped"

* Make table
esttab removing_sps_1  removing_sps_2 removing_ucsp_1 removing_ucsp_2 removing_both_1 removing_both_2 using "drafts/removing_rad_left.tex", tex se replace mtitles ("Removing SPS" "Removing SPS" "Removing UCSP" "Removing UCSP" "Removing both" "Removing both") keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* TABLE B15
* Open data
use data/referendums_data/data_both_plus_cmp_collapsed_no_unholly.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp)
est store no_unholly_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store no_unholly_2
estadd local  Errors "Bootstrapped"

* Make table
esttab no_unholly_1 no_unholly_2  using "drafts/no_unholly.tex", tex se replace nomtitles keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* TABLE B16
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Generate interaction
gen interaction5 = own_party_position_vote * rad_right_party

* Model 1
xtreg minority_groups own_party_position_vote interaction5 i.date, fe cluster(party_code_cmp)
est store party_vote_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups own_party_position_vote interaction5 i.date, fe vce(bootstrap, seed(2408))
est store party_vote_2
estadd local  Errors "Bootstrapped"

* Make table
esttab party_vote_1  party_vote_2  using "drafts/party_vote.tex", tex se replace nomtitles keep(own_party_position_vote interaction5 _cons) coeflabels (own_party_position_vote "Mean electoral support for party's position" interaction5 "Electoral support x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects") 

* TABLE B17
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Generate re-centered rile variable
sum rile_lag
gen rile_lag_recentered = rile_lag + 63.38
sum rile_lag_recentered

* Model 1
xtreg minority_groups c.own_party_position_surplus##c.rile_lag_recentered i.date if rad_right_party == 0, fe cluster(party_code_cmp)
est store other_parties_1
estadd local  Errors "Clustered"

* Model 2
xtreg minority_groups c.own_party_position_surplus##c.rile_lag_recentered  i.date if rad_right_party == 0, fe vce(bootstrap, seed(2408))
est store other_parties_2
estadd local  Errors "Bootstrapped"

* Make table
esttab other_parties_1  other_parties_2  using "drafts/other_parties.tex", tex se replace nomtitles keep(own_party_position_surplus _cons c.own_party_position_surplus#c.rile_lag_recentered) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" c.own_party_position_surplus#c.rile_lag_recentered "Electoral surplus x Lagged left-right position of party (CMP)" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("The outcome is a variable tapping positive mentions of minority groups by each party" "All models include party and year fixed effects" "The reference category is the most leftist party position found in the dataset") scalars(e(N))

* TABLE B18
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg v2xpa_antiplural own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store v2xpa_antiplural_1

* Model 2
xtreg v2paminor own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store v2paminor_1

* Model 3
xtreg v2paimmig own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store v2paimmig_1

* Model 4
xtreg v2palgbt own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store v2palgbt_1

* Model 5
xtreg v2paculsup own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store v2paculsup_1

* Make table
esttab v2xpa_antiplural_1 v2paminor_1 v2paimmig_1 v2palgbt_1 v2paculsup_1 using "drafts/vparty_cluster.tex", tex se replace mtitles ("Anti-pluralism" "Minority rights" "Support immigration" "Support LGBT social quality" "Opposes cultural superiority") keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party and year fixed effects" "Standard errors are clustered by party") scalars(e(N))

* TABLE B19
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg v2xpa_antiplural own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store v2xpa_antiplural_2

* Model 2
xtreg v2paminor own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store v2paminor_2

* Model 3
xtreg v2paimmig own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store v2paimmig_2

* Model 4
xtreg v2palgbt own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store v2palgbt_2

* Model 5
xtreg v2paculsup own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store v2paculsup_2

* Make table
esttab v2xpa_antiplural_2 v2paminor_2 v2paimmig_2 v2palgbt_2 v2paculsup_2 using "drafts/vparty_jk.tex", tex se replace mtitles ("Immigration pos" "Anti-pluralism" "Support immigration" "Support LGBT social quality" "Opposes cultural superiority") keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party and year fixed effects" "All models include bootstrap standard errors") scalars(e(N))

* TABLE B20
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg immigration_pos own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store immigration_pos_1

* Model 2
xtreg immigration_neg own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store immigration_neg_1

* Model 3
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store minority_groups_1

* Model 4
xtreg non_eco_dem_groups_pos own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store non_eco_dem_groups_pos_1

* Model 5
xtreg multiculturalism_pos own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store multiculturalism_pos_1

* Model 6
xtreg multiculturalism_neg own_party_position_surplus interaction4 i.date, fe cluster(party_code_cmp) 
est store multiculturalism_neg_1

* Make table
esttab immigration_pos_1 immigration_neg_1 minority_groups_1  non_eco_dem_groups_pos_1 multiculturalism_pos_1  multiculturalism_neg_1  using "drafts/other_outcomes_cluster.tex", tex se replace mtitles ("Immigration pos" "Immigration neg" "Minority groups pos" "Non eco dem groups pos" "Multiculturalism pos" "Multiculturalism neg") keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party and year fixed effects" "Standard errors are clustered by party") scalars(e(N))

* TABLE B21
* Open data
use data/referendums_data/data_plus_vparty.dta, clear

* Set data for fixed effects	
xtset party_code_cmp date

* Model 1
xtreg immigration_pos own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408)) 
est store immigration_pos_2

* Model 2
xtreg immigration_neg own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408)) 
est store immigration_neg_2

* Model 3
xtreg minority_groups own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store minority_groups_2

* Model 4
xtreg non_eco_dem_groups_pos own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store non_eco_dem_groups_pos_2

* Model 5
xtreg multiculturalism_pos own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408)) 
est store multiculturalism_pos_2

* Model 6
xtreg multiculturalism_neg own_party_position_surplus interaction4 i.date, fe vce(bootstrap, seed(2408))
est store multiculturalism_neg_2

* Make table
esttab immigration_pos_2 immigration_neg_2 minority_groups_2 non_eco_dem_groups_pos_2 multiculturalism_pos_2  multiculturalism_neg_2  using "drafts/other_outcomes_jk.tex", tex se replace mtitles ("Immigration pos" "Immigration neg" "Minority groups pos" "Non eco dem groups pos" "Multiculturalism pos" "Multiculturalism neg") keep(own_party_position_surplus interaction4 _cons) coeflabels (own_party_position_surplus "Mean electoral surplus in party's position" interaction4 "Electoral surplus x Far right party" _cons "Constant") s(Errors, label("Standard errors")) star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include party and year fixed effects"  "All models include bootstrap standard errors") scalars(e(N))

* Close log
translate session.smcl session.log, replace
translate session.smcl session.pdf, replace
